home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / basic / qbfaqr01.zip / PSP.DOC < prev    next >
Text File  |  1992-08-13  |  4KB  |  125 lines

  1.         ======== Exploring the PSP - by Brent Ashley =========
  2.  
  3.      DOS maintains various data structures to help it to organize 
  4. a running machine's memory.  One of these structures is the 
  5. Program Segment Prefix, which is a collection of information DOS 
  6. builds for an executing program.  The following discussion and the 
  7. accompanying program will give you all you need to access and 
  8. interpret the information stored in your program's PSP.
  9.  
  10.      The PSP is a 256-byte area which is reserved in memory 
  11. immediately before your program is loaded and run by the command 
  12. shell (usually COMMAND.COM).  Its structure follows, along with 
  13. typical uses of the information it contains. Offsets are in hex, 
  14. byte counts in decimal, and remember that intel processors store 
  15. numbers with lowest bytes first, ie 1234:5678 is stored as 78 56 
  16. 34 12.
  17.  
  18. ------------------------
  19.  
  20. OFFSET 0 - 2 Bytes
  21.  
  22.   There will always be the bytes CD 20 here - this is an INT 20h
  23.   call (terminate program).  It's here so programs can jump to
  24.   this location to terminate - not recommended, but it makes sense 
  25.   that programs which jump to an uninitialised (zero) address 
  26.   should be made to terminate in this way.
  27.  
  28. OFFSET 2 - 2 Bytes
  29.  
  30.   This is the segment address of the last paragraph of memory
  31.   allocated to the program.
  32.  
  33. OFFSET 5 - 5 Bytes
  34.  
  35.   There is a far call to the DOS function dispatcher here.  This 
  36.   is here only for CP/M compatibility and is never used.
  37.  
  38. OFFSET A - 4 Bytes
  39. OFFSET E - 4 Bytes
  40. OFFSET 12 - 4 Bytes
  41.  
  42.   These are the Segment:Offset Addresses to which control is 
  43.   passed:
  44.  
  45.   - upon termination of the program.
  46.   - when Control-Break is pressed.
  47.   - when a critical error is encountered.
  48.  
  49. OFFSET 16 - 2 Bytes
  50.  
  51.   The segment address of this program's parent program's PSP is 
  52.   stored here.
  53.  
  54. OFFSET 18 - 20 Bytes
  55.  
  56.   A table of 20 file handles is stored here.  Any program needing 
  57.   more than the default 20 file handles will need to use INT 21h 
  58.   function 67h to set the handle count to a number more than 20 
  59.   (but no more than FILES= in CONFIG.SYS).  This will cause DOS
  60.   to allocate a new file handle table of the size requested.  See
  61.   Offsets 2E, 30 also.
  62.  
  63. OFFSET 2C - 2 Bytes
  64.  
  65.   DOS provides each executable program with its own copy of the 
  66.   active Environment Strings at program load time.  This is the
  67.   segment address of this program's copy.  The environment strings 
  68.   block contains a list of strings, each terminated by a 00 byte, 
  69.   with a further 00 byte at the end of the list. At the end of the
  70.   environment strings, there is a 2-byte User Program signature
  71.   which, when set to 1 (01 00), signifies the program's full path 
  72.   specification can be found in the following bytes, teminated 
  73.   with a null (00) byte.
  74.  
  75. OFFSET 2E - 2 Bytes
  76.  
  77.   This is the number of file handles in the current handle table.
  78.  
  79. OFFSET 30 - 4 Bytes
  80.  
  81.   Segment:Offset address of the file handle table, either the one 
  82.   here in the PSP, or the one allocated with INT 21h svc 67h.  
  83.  
  84. OFFSET 5C - 16 Bytes
  85. OFFSET 6C - 16 Bytes
  86.  
  87.   There are two unopened File Control Blocks constructed here as 
  88.   part of the program load process, based on the command line 
  89.   entered when the current progam was invoked.  It's interesting 
  90.   to note that DOS has already parsed the drive, filename and 
  91.   extension and placed it here, but only if there is no path 
  92.   information included, since FCBs are a throwback from when DOS 
  93.   didn't have a heirarchical directory structure.
  94.  
  95. OFFSET 80 - 1 Byte
  96. OFFSET 81 - 127 Bytes
  97.  
  98.   The length of the command line entered after the program name 
  99.   when the program was invoked is stored here, followed by the 
  100.   command line itself.  The default Disk Transfer Area for this 
  101.   program is also here, so unless your program sets its own
  102.   (which most do), the command line information could be
  103.   overwritten.  You might want to get the command line information 
  104.   from here because QB uppercases it and trims it before passing
  105.   it to you via COMMAND$.
  106.  
  107. ------------------------
  108.  
  109.   The accompanying program, PSP.BAS, shows how you can access and 
  110. interpret the PSP.  Remember that when using it in the QB 
  111. development environment, the PSP it will be looking at is that of 
  112. the environment.  A good test for the program will be to invoke it 
  113. as follows:
  114.  
  115. PSP A:FILENAME.EXT B:OUTFILE.TST
  116.  
  117. Have Fun!
  118.  
  119. -----
  120. Brent
  121. -----
  122.  
  123. <EOF>
  124.  
  125.